package 购票thread框的形式;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

public class Test extends JFrame{
    private JTextArea[] ta=new JTextArea[3];
    public Test(){
        setTitle("售票");
        setSize(1000,500);
        setVisible(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLayout(null);
        int x=40;
        for(int i=0;i<3;i++){
            ta[i]=new JTextArea();
            JScrollPane sp=new JScrollPane(ta[i]);
            sp.setBounds(x,10,300,300);
            add(sp);
            x+=310;
        }
        JButton btn=new JButton("开始");
        btn.setBounds(400,350,200,25);
        add(btn);
        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                for(int i=0;i<3;i++)
                    ta[i].setText("");
                List<Ticks> lists=new ArrayList<>();
                for(int i=0;i<20;i++){
                    lists.add(new Ticks(i+1));
                }
                SailTick st1=new SailTick(lists,ta[0]);
                SailTick st2=new SailTick(lists,ta[1]);
                SailTick st3=new SailTick(lists,ta[2]);
                st1.start();st2.start();st3.start();
                //查看线程
                while (true){
                    if(!st1.isAlive()&&!st2.isAlive()&&st3.isAlive())break;
                    System.out.println(st1.getState());
                    System.out.println(st2.getState());
                    System.out.println(st3.getState());
                }
            }
        });
    }
    public static void main(String[] args){
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new Test();
            }
        });
    }
}
